Results 1 to 9 of 9

Thread: Referencing Script to Script

  1. #1

    Default Referencing Script - Achievement Tracking

    Hey again!

    I am adding achievements to my botserver based on kills, kills with certain weapons and linking some other in-game events to achievements.

    First one is an edit of the existing Funcrate mod. Idea is: Find the hidden crate. when the crate is shot, it explodes and the achievement pops!

    But I am getting "Cannot cast 'NIL' to listener" errors, even though I have defined NIL to 0 with an IF statement already.

    Any ideas or suggestions?!

    Funcrate Script I added a "local.player.cratexplode" to the script to reference. All my additions are in bold/red. But these may be incorrect approaches.....

    Code:
    main local.model local.origin local.angles local.type local.respawn:
    
    
            // Setting Crate Achievement Settings --> linked to Scoreboardname.scr
            
            local.player.cratexplode = 0
    
            if (local.player.cratexplode == NIL)
                local.player.cratexplode = 0
    
    
            //Start Fun-Crate Script
    
    	local.ent = spawn script_object origin local.origin model local.model
    	local.ent notsolid
    	local.ent.angles = local.angles
    	local.BBox = local.ent waitthread GetBBox
    	local.trig = spawn trigger_multiple origin local.origin spawnflags 128 health 100
    	local.trig setsize ( local.BBox[0] local.BBox[1] local.BBox[2] ) ( local.BBox[3] local.BBox[4] local.BBox[5] )
    	local.trig.angles = local.angles
    	local.direction[1] = angles_toforward local.ent.angles * 400 + ( 0 0 300 )
    	local.direction[2] = angles_toforward local.ent.angles * 400 + ( 0 0 600 )
    	local.direction[3] = angles_toleft local.ent.angles * 400 + ( 0 0 100 )
    	local.direction[4] = angles_toleft local.ent.angles * 400 + ( 0 0 -300 )
    	local.direction[5] = angles_toup local.ent.angles * 400 + ( 0 0 500 )
    	local.direction[6] = angles_toup local.ent.angles * 400 + ( 0 0 200 )
    	local.ent thread SafeSolid
    	local.trig waittill trigger
    	local.trig nottriggerable
    	local.player = parm.other
    	if(local.type != NIL)
    		thread Explosion local.player local.origin
    	local.ent remove
    	local.trig playsound snd_crate_wood
    	local.trig remove
    	for(local.i=1;local.i<7;local.i++)
    		{
    		local.deb[local.i] = spawn script_object model models/fx/crates/crate-jib-chunk.tik origin local.origin
    		local.deb[local.i] notsolid
    		local.deb[local.i] physics_on
    		local.deb[local.i].velocity = local.direction[local.i]
    		local.deb[local.i] rotatex 100
    		local.deb[local.i] rotatez 100
    		local.deb[local.i] commanddelay 3 remove
    		}
    	if(local.respawn != NIL)
    		{
    		local.time = int local.respawn
    		wait local.time
    		thread main local.model local.origin local.angles local.type local.respawn
    		}
    
    end
    
    end
    
    SafeSolid:
    
    	while(1)
    		{
    		local.loop = NIL
    		for(local.i=1;local.i<=$player.size;local.i++)
    			if($player[local.i] istouching self)
    				local.loop = 1
    		if(local.loop == NIL)
    			break
    		waitframe
    		}
    	self solid
    end
    
    Explosion local.player local.origin:
    
    	local.fx = spawn models/emitters/fx_explosion_mine.tik origin local.origin
    	local.fx anim start
    	for(local.i=1;local.i<=$player.size;local.i++)
    		{
    		local.dist = ( $player[local.i].origin - local.fx.origin )	
    		local.sqr = local.dist * local.dist	
    		local.radius = 300.0 * 300.0
    		if(local.sqr <= local.radius)	
    			{
    			if(getcvar g_teamdamage == 1 || int (getcvar(g_gametype)) == 1)
    				{
    				$player[local.i] damage local.player 100 local.player $player[local.i].origin $player[local.i].forwardvector ( 0 0 0 ) 0 0 9 0
    				}
    			else
    				{
    				//if($player[local.i].dmteam != self.dmteam)
    				$player[local.i] damage local.player 100 local.player $player[local.i].origin $player[local.i].forwardvector ( 0 0 0 ) 0 0 9 0
    				}
    			}
    		}
            //Start Achievement tracking
    
            local.player.cratexplode = 1
    
    	//End Achievement tracking
    
            wait 1
    	local.fx remove
    
    end
    
    
    GetBBox:
    
    	local.origin = self.origin
    	local.item = spawn script_origin origin local.origin
    	local.item.angles = self.angles
    	local.item setsize ( 0 0 0 ) ( 0 0 0 )
    
    	local.setsize[0] = 0
    	local.setsize[1] = 0
    	local.setsize[2] = 0
    	local.setsize[3] = 0
    	local.setsize[4] = 0
    	local.setsize[5] = 0
    
    	//backwards
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * -10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * -10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//right
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * -10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * -10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//down
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toup local.item.angles) * -10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toup local.item.angles) * -10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//up
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toup local.item.angles) * 10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toup local.item.angles) * 10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i + 3] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//left
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * 10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * 10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i + 3] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//forward
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * 10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * 10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i + 3] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    	local.item remove
    
    	//println ("[Get Bounding Box]Return Value: ( " + local.setsize[0] + " " + local.setsize[1] + " " + local.setsize[2] + " ) ( " + local.setsize[3] + " " + local.setsize[4] + " " + local.setsize[5] + " )")
    
    
    end local.setsize

    I then call on the above script from a separate achievement-related script.
    I will probably use a globalwidget for the hud message later, but for the moment, entry looks like:

    Code:
     if (local.player.cratexplode = 1)
                 local.player.achievement = local.player.achievement + 1 
    
               if(local.player.cratexplode = 1)
     	      locprint 140 80 ("Achievement Unlocked: Lost my Box!")
    
               if(local.player.cratexplode = 1)
                  local.player playsound announce13
    But I keep getting NIL errors. Any ideas how I can get this working? Cheers as always!
    Last edited by OhGaz; October 12th, 2015 at 04:59 AM.

  2. #2
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    It is because
    local.player
    Is not defined as anything, just a local variable.
    local.player by itself does not mean anything, it is just a common variable named used when referencing a player, but in this case you have not defined the player.
    So local.player is just a variable that points to nothing.
    It is not a pre-defined game variable to a player

    $player is an array of players, thats why you seen a lot of
    local.player = $player[local.i]
    Which assigns a local variable player with that player entity from the array of players.

    Does that make sense?

    Mainly you need to assign the player entity to local.player within the script or parse it from another script.

    local variables are local, as the name implies.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  3. #3

    Default

    Thanks Purple - Indeed, that makes sense, I think.

    I tried defining that value, but my script breaks or I still get "Script Error: Cannot cast 'NIL' to listener".

    I tried adding this to the beginning:, but that didnt help either.

    Code:
    while(1) {
        for(local.i = 1; local.i <= $player.size; local.i++) {
            local.player = $player[local.i];
            if (!local.player.has_client_id_displayed) {
                local.player.has_client_id_displayed = 1;
    So I took out my changes. Below in red is where the explosion happens and this where I think the achievement entry needs to go (I think).

    I also noticed that there is a local.player=parm.other in there already if that conflicts?

    I had planned to create say a local.player.crateexplode, then set to 1 in this script when crate explodes.
    And then call on it in my other achievement script to display it onscreen/count it to my achievement tally.
    Maybe I am thinking about this completely wrong?

    Any suggestions of what to put in, would be awesome...

    Thanks muchly again, all!

    Code:
    main local.model local.origin local.angles local.type local.respawn:
    
    	local.ent = spawn script_object origin local.origin model local.model
    	local.ent notsolid
    	local.ent.angles = local.angles
    	local.BBox = local.ent waitthread GetBBox
    	local.trig = spawn trigger_multiple origin local.origin spawnflags 128 health 100
    	local.trig setsize ( local.BBox[0] local.BBox[1] local.BBox[2] ) ( local.BBox[3] local.BBox[4] local.BBox[5] )
    	local.trig.angles = local.angles
    	local.direction[1] = angles_toforward local.ent.angles * 400 + ( 0 0 300 )
    	local.direction[2] = angles_toforward local.ent.angles * 400 + ( 0 0 600 )
    	local.direction[3] = angles_toleft local.ent.angles * 400 + ( 0 0 100 )
    	local.direction[4] = angles_toleft local.ent.angles * 400 + ( 0 0 -300 )
    	local.direction[5] = angles_toup local.ent.angles * 400 + ( 0 0 500 )
    	local.direction[6] = angles_toup local.ent.angles * 400 + ( 0 0 200 )
    	local.ent thread SafeSolid
    	local.trig waittill trigger
    	local.trig nottriggerable
    	local.player = parm.other
    	if(local.type != NIL)
    		thread Explosion local.player local.origin
               // ENTER ACHIEVEMENT CODE HERE
                   // (Consider local.player.achievement or local.player.crateexplode)
    	local.ent remove
    	local.trig playsound snd_crate_wood
    	local.trig remove
    	for(local.i=1;local.i<7;local.i++)
    		{
    		local.deb[local.i] = spawn script_object model models/fx/crates/crate-jib-chunk.tik origin local.origin
    		local.deb[local.i] notsolid
    		local.deb[local.i] physics_on
    		local.deb[local.i].velocity = local.direction[local.i]
    		local.deb[local.i] rotatex 100
    		local.deb[local.i] rotatez 100
    		local.deb[local.i] commanddelay 3 remove
    		}
    	if(local.respawn != NIL)
    		{
    		local.time = int local.respawn
    		wait local.time
    		thread main local.model local.origin local.angles local.type local.respawn
    		}
    
    end
    
    end
    
    SafeSolid:
    
    	while(1)
    		{
    		local.loop = NIL
    		for(local.i=1;local.i<=$player.size;local.i++)
    			if($player[local.i] istouching self)
    				local.loop = 1
    		if(local.loop == NIL)
    			break
    		waitframe
    		}
    	self solid
    end
    
    Explosion local.player local.origin:
    
    	local.fx = spawn models/emitters/fx_explosion_mine.tik origin local.origin
    	local.fx anim start
    	for(local.i=1;local.i<=$player.size;local.i++)
    		{
    		local.dist = ( $player[local.i].origin - local.fx.origin )	
    		local.sqr = local.dist * local.dist	
    		local.radius = 300.0 * 300.0
    		if(local.sqr <= local.radius)	
    			{
    			if(getcvar g_teamdamage == 1 || int (getcvar(g_gametype)) == 1)
    				{
    				$player[local.i] damage local.player 100 local.player $player[local.i].origin $player[local.i].forwardvector ( 0 0 0 ) 0 0 9 0
    				}
    			else
    				{
    				//if($player[local.i].dmteam != self.dmteam)
    				$player[local.i] damage local.player 100 local.player $player[local.i].origin $player[local.i].forwardvector ( 0 0 0 ) 0 0 9 0
    				}
    			}
    		}
    	wait 1
    	local.fx remove
    
    end
    
    
    GetBBox:
    
    	local.origin = self.origin
    	local.item = spawn script_origin origin local.origin
    	local.item.angles = self.angles
    	local.item setsize ( 0 0 0 ) ( 0 0 0 )
    
    	local.setsize[0] = 0
    	local.setsize[1] = 0
    	local.setsize[2] = 0
    	local.setsize[3] = 0
    	local.setsize[4] = 0
    	local.setsize[5] = 0
    
    	//backwards
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * -10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * -10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//right
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * -10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * -10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//down
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toup local.item.angles) * -10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toup local.item.angles) * -10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//up
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toup local.item.angles) * 10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toup local.item.angles) * 10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i + 3] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//left
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * 10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toleft local.item.angles) * 10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i + 3] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    
    	//forward
    
    	local.item.origin = local.origin
    
    	local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * 10)
    	local.item.origin = local.grid 
    
    	while(1)
    		{
    		if(local.item istouching self)
    			{
    			local.grid = (local.item.origin  +  (angles_toforward local.item.angles) * 10)
    			local.item.origin = local.grid
    			}
    		else
    			break
    		waitframe
    		}
    
    	for(local.i=0;local.i<3;local.i++)
    		{
    		if(local.grid[local.i] != local.origin[local.i])
    			{
    			local.setsize[local.i + 3] = (local.grid[local.i] - local.origin[local.i])
    			break
    			}
    		}
    
    	local.item remove
    
    	//println ("[Get Bounding Box]Return Value: ( " + local.setsize[0] + " " + local.setsize[1] + " " + local.setsize[2] + " ) ( " + local.setsize[3] + " " + local.setsize[4] + " " + local.setsize[5] + " )")
    
    
    end local.setsize
    Last edited by OhGaz; October 12th, 2015 at 10:55 PM.

  4. #4
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Oh i see what your trying to do, i think anyway.

    Yes you can add the code there,
    parm.other is a predefined variable which changes depending on the circumstances, in this case, to the entity that activated the trigger.
    So local.player = parm.other will set the local.player to the actual player which triggered it.

    So now you need to just check if local.player.achievement is NILL, NULL and if it is , set to 0, or increment.

    .
    ..
    ....
    .....
    local.trig nottriggerable
    local.player = parm.other
    if(local.type != NIL)
    thread Explosion local.player local.origin
    // ENTER ACHIEVEMENT CODE HERE
    // (Consider local.player.achievement or local.player.crateexplode)
    if(local.player.achievement == NIL || local.player.achievement == NULL)  /// if nil, set to 0
    local.player.achievement = 0;
    
    local.player.achievement++;  /// increments it
    ///ABOVE
    local.ent remove
    local.trig playsound snd_crate_wood
    .....
    ..
    .


    EDIT::: Also you might want to add a check to make sure that parm.other is a player, before you do that, but either way it shouldnt really matter.

    Also if you intend to use it within another script, its probably best to actually call it within this script, instead of just having a loop continuously monitoring the achievement variable.
    Last edited by Purple Elephant1au; October 12th, 2015 at 11:12 PM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  5. #5

    Default

    Genius as always, Purple. Thanks. I used your way, but with local.player.cratex cumulating to the achievement score - and worked well.

    I think I have the order wrong in my other script for the achievements, however...

    Eg - all achievements on killing bot #'s (local.player.bot_killcount) cumulate to my achievement HUD counter all ok.
    But the other figures (eg human kills: local.player.killcount and achievement count: local.player.achievement) only get updated to the HUD when a bot is killed (ie when local.player.bot_killcount is called).

    I think this is related to the below - code that I am using to avoid unnecessarily checking for changes.

    Code:
    }
            
            if (local.player.killcount == NIL)
                local.player.killcount = 0
    
            if (local.player.bot_killcount == NIL)
                local.player.bot_killcount = 0        
    
            if (local.player.deathcount == NIL)
                local.player.deathcount = 0
    
            if (local.player.achievement == NIL)
                local.player.achievement = 0
    
            if (local.player.deathcount_displayed != local.player.deathcount)
                local.player.deathcount_displayed = local.player.deathcount;
    
            if (local.player.kills_displayed != local.player.killcount)
                local.player.kills_displayed = local.player.killcount;
    
            if (local.player.bot_kills_displayed != local.player.bot_killcount) {
                local.player.bot_kills_displayed = local.player.bot_killcount;
    
            if (local.player.achievement_displayed != local.player.achievement)
                local.player.achievement_displayed = local.player.achievement;
    Is there a way to rephrase the above so that when ANY of the values of local.player.bot_killcount, local.player.killcount or local.player.achievement increase, it is updated immediately on my HUD widgets?
    Last edited by OhGaz; October 13th, 2015 at 07:25 AM.

  6. #6

    Default

    Quote Originally Posted by OhGaz View Post
    I think this is related to the below - code that I am using to avoid unnecessarily checking for changes.
    In your code below, you must also initialize the _displayed variables like others. It won't work with (nil) == (rval).

    Quote Originally Posted by OhGaz View Post
    Is there a way to rephrase the above so that when ANY of the values of local.player.bot_killcount, local.player.killcount or local.player.achievement increase, it is updated immediately on my HUD widgets?
    This is not possible you also have to update your HUD widgets along with code that update values.

  7. #7

    Default

    Ok, thanks Ley0k, and all. Appreciated.

    So I am understanding:

    1. We are saying that I need to add the equivalent of: local.player.bot_killcount_displayed == NIL, local.player.bot_killcount_displayed = 0 for each displayed call? Correct?

    And

    2. We are saying that it's not possible to update multiple widget HUDS when their count cumulates, and that I can only rely on the outcomes of one?

    Here is an excerpt from my achievement thread that I've got now, if it helps. I have a separate firework script that adds an achievement point to local.player.achievement when a firework is launched, so all in all, it would be great to see the level.player.achievement HUD counter kick over when the event occurs, without having to wait for the next player.bot_kill event, for it to appear.

    Code:
            }
            
            if (local.player.killcount == NIL)
                local.player.killcount = 0
    
            if (local.player.bot_killcount == NIL)
                local.player.bot_killcount = 0        
    
            if (local.player.deathcount == NIL)
                local.player.deathcount = 0
    
            if (local.player.achievement == NIL)
                local.player.achievement = 0
    
            if (local.player.deathcount_displayed != local.player.deathcount)
                local.player.deathcount_displayed = local.player.deathcount;
    
            if (local.player.kills_displayed != local.player.killcount)
                local.player.kills_displayed = local.player.killcount;
    
            if (local.player.bot_kills_displayed != local.player.bot_killcount) {
                local.player.bot_kills_displayed = local.player.bot_killcount;
    
            if (local.player.achievement_displayed != local.player.achievement) 
                local.player.achievement_displayed = local.player.achievement;
    
    
    
    // WIDGET 2 DISPLAYS BOT KILLS AND HUMAN KILLS 
       
                local.player stufftext "globalwidgetcommand dday2 fgcolor 1.00 1.00 1.00 1.00"
                local.player stufftext "globalwidgetcommand dday2 bgcolor 0.00 0.00 0.00 0.00"
                local.player stufftext "globalwidgetcommand dday2 fadein 0"
                local.player stufftext "globalwidgetcommand dday2 menu dday2 640 480 NONE 0"
                local.player stufftext "globalwidgetcommand dday2 virtualres 1" 
                local.player stufftext "globalwidgetcommand dday2 fullscreen 0"
                local.player stufftext "globalwidgetcommand dday2 bgfill 0 0 0 0.00"
             
                local.player stufftext "globalwidgetcommand charliesector rect 65 100 -10 100 100"
                local.player stufftext "globalwidgetcommand charliesector fgcolor 1.00 1.00 1.00 1.00"
                local.player stufftext "globalwidgetcommand charliesector bgcolor 0.00 0.00 0.00 0.00"
                local.player stufftext "globalwidgetcommand charliesector font handle-16"
                local.player stufftext "globalwidgetcommand charliesector align 64 center bottom"
                local.player stufftext "globalwidgetcommand charliesector virtualsize 64 1
                local.player stufftext "globalwidgetcommand charliesector shader townhallwindow"
                local.player stufftext ("set bot_kill_msg Bot Frags: " + local.player.bot_killcount + " / Human Frags: " + local.player.killcount);
                local.player stufftext "globalwidgetcommand charliesector linkcvar bot_kill_msg"
                local.player stufftext "showmenu dday2"
    
    
            
    // COUNTER FOR ACHIEVEMENTS, MESSAGE AND SOUND
    
           if (local.player.bot_killcount == 2)
              local.player.achievement = local.player.achievement + 1
    
           if (local.player.bot_killcount == 2)
    	  iprintlnbold_noloc ("Achievement Unlocked: 2 BOTS PWNED!!")
    
           if (local.player.bot_killcount == 2)
    	  local.player playsound announce13
          
     
    // WIDGET 3 - DISPLAYS ACHIEVEMENTS   
    
    
    	    local.player stufftext "globalwidgetcommand credits2 name credits1"
    	    local.player stufftext "globalwidgetcommand credits1 shader townhallwindow"
    	    local.player stufftext "globalwidgetcommand credits1 fgcolor 1.00 0.00 1.00 1.00"
    	    local.player stufftext "globalwidgetcommand credits1 bgcolor 0.00 0.00 0.00 0.00"
    	    local.player stufftext "globalwidgetcommand credits1 fadein 0"
    	    local.player stufftext "globalwidgetcommand credits1 menu credits2 640 480 NONE 0"
    	    local.player stufftext "globalwidgetcommand credits1 virtualres 1"
    	    local.player stufftext "globalwidgetcommand credits1 fullscreen 0"
    	    local.player stufftext "globalwidgetcommand credits1 name credits2"
    
    	    local.player stufftext "globalwidgetcommand credits1 rect 66 -150 -10 100 100"
    	    local.player stufftext "globalwidgetcommand credits1 fgcolor 1.00 3.00 4.00 6.00"
    	    local.player stufftext "globalwidgetcommand credits1 bgcolor 0.00 0.00 0.00 0.00"
                local.player stufftext "globalwidgetcommand credits1 align 66 right bottom"
                local.player stufftext "globalwidgetcommand credits1 virtualsize 66 1
    	    local.player stufftext "globalwidgetcommand credits1 font handle-16"
    	    local.player stufftext "globalwidgetcommand credits1 shader townhallwindow"
    	    local.player stufftext ("set achievement_msg Achievements: " + local.player.achievement + " / 10 Points");
    	    local.player stufftext "globalwidgetcommand credits1 linkcvar achievement_msg"
    	    local.player stufftext "showmenu credits1"
    
    
            }
        }
        wait 1
    }
    
    end
    Thanks again.
    Last edited by OhGaz; October 13th, 2015 at 06:44 PM.

  8. #8
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Put the widgets in a separate thread and just call it each time you increment the achievement.

    I am guessing there is a loop involved there somewhere? hard to be sure without all the code.

    What do you use the
    local.player.achievement_displayed

    variable for?

    Run us through what exactly you are trying to achieve.

    I think i got it,
    You have added an achievement point system to a bot scoreboard. and you have certain achievement events that increment the points.
    Am i kinda right?
    But atm you cant find a way to update the widgets until the a bot is killed?? because im guessing the above code is within the thread that handles all that?

    Basically you need to create a thread outside of the main thread, so you can call it from outside the script(ie other scripts) .

    Most of what is typed above can go in a thread.
    .
    ...
    .....
        if(!local.player.init_count)
        {
            local.player.killcount = 0;
            local.player.bot_killcount = 0;
            local.player.deathcount = 0;
            local.player.achievement = 0;
    
            local.player.init_count = 1;
        }
    
       if (local.player.bot_killcount == 2)
       {
            local.player.achievement++;
            local.player iprintlnbold_noloc ("Achievement Unlocked: 2 BOTS PWNED!!");
            local.player playsound announce13;
        }
        // then call update widget thread
        waitthread update_widget local.player;
    ...
    ..
    .
    
    update_widget local.player:
    
    // WIDGET 2 DISPLAYS BOT KILLS AND HUMAN KILLS
    
    local.player stufftext "globalwidgetcommand dday2 fgcolor 1.00 1.00 1.00 1.00"
    local.player stufftext "globalwidgetcommand dday2 bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand dday2 fadein 0"
    local.player stufftext "globalwidgetcommand dday2 menu dday2 640 480 NONE 0"
    local.player stufftext "globalwidgetcommand dday2 virtualres 1"
    local.player stufftext "globalwidgetcommand dday2 fullscreen 0"
    local.player stufftext "globalwidgetcommand dday2 bgfill 0 0 0 0.00"
    
    local.player stufftext "globalwidgetcommand charliesector rect 65 100 -10 100 100"
    local.player stufftext "globalwidgetcommand charliesector fgcolor 1.00 1.00 1.00 1.00"
    local.player stufftext "globalwidgetcommand charliesector bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand charliesector font handle-16"
    local.player stufftext "globalwidgetcommand charliesector align 64 center bottom"
    local.player stufftext "globalwidgetcommand charliesector virtualsize 64 1
    local.player stufftext "globalwidgetcommand charliesector shader townhallwindow"
    local.player stufftext ("set bot_kill_msg Bot Frags: " + local.player.bot_killcount + " / Human Frags: " + local.player.killcount);
    local.player stufftext "globalwidgetcommand charliesector linkcvar bot_kill_msg"
    local.player stufftext "showmenu dday2"
    
    
    // WIDGET 3 - DISPLAYS ACHIEVEMENTS
    
    local.player stufftext "globalwidgetcommand credits2 name credits1"
    local.player stufftext "globalwidgetcommand credits1 shader townhallwindow"
    local.player stufftext "globalwidgetcommand credits1 fgcolor 1.00 0.00 1.00 1.00"
    local.player stufftext "globalwidgetcommand credits1 bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand credits1 fadein 0"
    local.player stufftext "globalwidgetcommand credits1 menu credits2 640 480 NONE 0"
    local.player stufftext "globalwidgetcommand credits1 virtualres 1"
    local.player stufftext "globalwidgetcommand credits1 fullscreen 0"
    local.player stufftext "globalwidgetcommand credits1 name credits2"
    
    local.player stufftext "globalwidgetcommand credits1 rect 66 -150 -10 100 100"
    local.player stufftext "globalwidgetcommand credits1 fgcolor 1.00 3.00 4.00 6.00"
    local.player stufftext "globalwidgetcommand credits1 bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand credits1 align 66 right bottom"
    local.player stufftext "globalwidgetcommand credits1 virtualsize 66 1
    local.player stufftext "globalwidgetcommand credits1 font handle-16"
    local.player stufftext "globalwidgetcommand credits1 shader townhallwindow"
    local.player stufftext ("set achievement_msg Achievements: " + local.player.achievement + " / 10 Points");
    local.player stufftext "globalwidgetcommand credits1 linkcvar achievement_msg"
    local.player stufftext "showmenu credits1"
    
    end

    Then if you need to update the widgets from outside that loop or script, then just
    incremeent the points
    call the update_widget thread and parse local.player.
    Example
    Code:
    
    
    Code:
    // ENTER ACHIEVEMENT CODE HERE
    // (Consider local.player.achievement or local.player.crateexplode)
    if(local.player.achievement == NIL || local.player.achievement == NULL)  /// if nil, set to 0
    local.player.achievement = 0;
    
    local.player.achievement++;  /// increments it
    global/the_bot_script.scr::update_widget local.player
    ///ABOVE
    




    Last edited by Purple Elephant1au; October 14th, 2015 at 01:04 AM.

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  9. #9

    Default

    Hey purple - thanks that indeed worked now with the "External script events" adding to the local.player.achievement immediately.

    But unfortunately it's screwed up the bot_kill counter - it runs in an infinite loop, continuously adding kills and looping the audio cue upon the first bot_kill. Simple error on my part probably I know......

    Also now getting an error based on the first while statement....

    Code:
    for(local.i = 1; local.i <= $player.size; local.i++) { (custom/achievements.scr, 27)
        for(local.i = 1; local.i ^
    
    ^~^~^ Script Error: binary '<=' applied to incompatible types 'NIL' and 'int
    Here's the full script now. Sorry for trouble, but I think I'm close...

    Code:
    main:
    
    
    //*** Sounds
    local.master = spawn ScriptMaster
    local.master aliascache announce0 sounds/announcer/firstblood.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce1 sounds/announcer/double_kill.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce2 sounds/announcer/dominating.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce3 sounds/announcer/holyshit.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce4 sounds/announcer/killingspree.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce5 sounds/announcer/rampage.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce6 sounds/announcer/unstoppable.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce7 sounds/announcer/ultrakill.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce8 sounds/announcer/pokersound.wav soundparms 5 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce9 sounds/announcer/children.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce10 sounds/announcer/godlike.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce11 sounds/announcer/headshot.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce12 sounds/announcer/monsterkill.wav soundparms 2 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    local.master aliascache announce13 sounds/announcer/multikill.wav soundparms 4 0.1 0.9 0.2 320 4000 voice loaded maps "m dm obj"
    
    
    while(1) {
        for(local.i = 1; local.i <= $player.size; local.i++) {
            local.player = $player[local.i];
            if (!local.player.has_client_id_displayed) {
                local.player.has_client_id_displayed = 1;
    
    // Widget 1 DISPLAYS CLIENT ID
    
                local.player stufftext "globalwidgetcommand dday1 fgcolor 1.00 1.00 1.00 1.00"
                local.player stufftext "globalwidgetcommand dday1 bgcolor 0.00 0.00 0.00 0.00"
                local.player stufftext "globalwidgetcommand dday1 fadein 0"
                local.player stufftext "globalwidgetcommand dday1 menu dday1 640 480 NONE 0"
                local.player stufftext "globalwidgetcommand dday1 virtualres 1" 
                local.player stufftext "globalwidgetcommand dday1 fullscreen 0"
                local.player stufftext "globalwidgetcommand dday1 bgfill 0 0 0 0.00"
             
                local.player stufftext "globalwidgetcommand june6 rect 64 40 -10 100 100"
                local.player stufftext "globalwidgetcommand june6 fgcolor 1.00 1.00 1.00 1.00"
                local.player stufftext "globalwidgetcommand june6 bgcolor 0.00 0.00 0.00 0.00"
                local.player stufftext "globalwidgetcommand june6 font handle-16"
                local.player stufftext "globalwidgetcommand june6 align 64 left bottom"
                local.player stufftext "globalwidgetcommand june6 virtualsize 64 1
                local.player stufftext "globalwidgetcommand june6 shader townhallwindow"
                local.player stufftext ("set client_id_msg You are Player: " + local.player.entnum);
                local.player stufftext "globalwidgetcommand june6 linkcvar client_id_msg"
                local.player stufftext "showmenu dday1"
          
            }
            
            if (local.player.killcount == NIL)
                local.player.killcount = 0
    
            if (local.player.bot_killcount == NIL)
                local.player.bot_killcount = 0        
    
            if (local.player.deathcount == NIL)
                local.player.deathcount = 0
    
            if (local.player.achievement == NIL)
                local.player.achievement = 0
    
            if (local.player.deathcount_displayed != local.player.deathcount)
                local.player.deathcount_displayed = local.player.deathcount;
    
            if (local.player.kills_displayed != local.player.killcount)
                local.player.kills_displayed = local.player.killcount;
    
            if (local.player.bot_kills_displayed != local.player.bot_killcount)
                local.player.bot_kills_displayed = local.player.bot_killcount;
    
            if (local.player.achievement_displayed != local.player.achievement) 
                local.player.achievement_displayed = local.player.achievement;
    
            {
    
    if(!local.player.init_count)
        {
            local.player.killcount = 0;
            local.player.bot_killcount = 0;
            local.player.deathcount = 0;
            local.player.achievement = 0;
    
            local.player.init_count = 1;
        }
            
       if (local.player.bot_killcount == 1)
       {
            local.player.achievement = local.player.achievement + 1;
            local.player iprintlnbold_noloc ("Achievement Unlocked: AWW. YOU KILLED A BOT. BIG MAN ON CAMPUS!!!");
            local.player playsound announce0;
        }
        // then call update widget thread 
        waitthread update_widget local.player;
    
     if (local.player.bot_killcount == 2)
       {
            local.player.achievement = local.player.achievement + 1;
            local.player locprint 140 80 ("Achievement Unlocked: 2 BOTS PWNED! HERE. WE. GO!");
            local.player playsound announce1;
        }
        // then call update widget thread 
        waitthread update_widget local.player;
    
    update_widget local.player:
    
    
    // WIDGET 2 DISPLAYS BOT KILLS AND HUMAN KILLS
    
    local.player stufftext "globalwidgetcommand dday2 fgcolor 1.00 1.00 1.00 1.00"
    local.player stufftext "globalwidgetcommand dday2 bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand dday2 fadein 0"
    local.player stufftext "globalwidgetcommand dday2 menu dday2 640 480 NONE 0"
    local.player stufftext "globalwidgetcommand dday2 virtualres 1"
    local.player stufftext "globalwidgetcommand dday2 fullscreen 0"
    local.player stufftext "globalwidgetcommand dday2 bgfill 0 0 0 0.00"
    
    local.player stufftext "globalwidgetcommand charliesector rect 65 100 -10 100 100"
    local.player stufftext "globalwidgetcommand charliesector fgcolor 1.00 1.00 1.00 1.00"
    local.player stufftext "globalwidgetcommand charliesector bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand charliesector font handle-16"
    local.player stufftext "globalwidgetcommand charliesector align 64 center bottom"
    local.player stufftext "globalwidgetcommand charliesector virtualsize 64 1
    local.player stufftext "globalwidgetcommand charliesector shader townhallwindow"
    local.player stufftext ("set bot_kill_msg Bot Frags: " + local.player.bot_killcount + " / Human Frags: " + local.player.killcount);
    local.player stufftext "globalwidgetcommand charliesector linkcvar bot_kill_msg"
    local.player stufftext "showmenu dday2"
    
    // WIDGET 3 - DISPLAYS ACHIEVEMENTS   
    
    local.player stufftext "globalwidgetcommand credits2 name credits1"
    local.player stufftext "globalwidgetcommand credits1 shader townhallwindow"
    local.player stufftext "globalwidgetcommand credits1 fgcolor 1.00 0.00 1.00 1.00"
    local.player stufftext "globalwidgetcommand credits1 bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand credits1 fadein 0"
    local.player stufftext "globalwidgetcommand credits1 menu credits2 640 480 NONE 0"
    local.player stufftext "globalwidgetcommand credits1 virtualres 1"
    local.player stufftext "globalwidgetcommand credits1 fullscreen 0"
    local.player stufftext "globalwidgetcommand credits1 name credits2"
    
    local.player stufftext "globalwidgetcommand credits1 rect 66 -150 -10 100 100"
    local.player stufftext "globalwidgetcommand credits1 fgcolor 1.00 3.00 4.00 6.00"
    local.player stufftext "globalwidgetcommand credits1 bgcolor 0.00 0.00 0.00 0.00"
    local.player stufftext "globalwidgetcommand credits1 align 66 right bottom"
    local.player stufftext "globalwidgetcommand credits1 virtualsize 66 1
    local.player stufftext "globalwidgetcommand credits1 font handle-16"
    local.player stufftext "globalwidgetcommand credits1 shader townhallwindow"
    local.player stufftext ("set achievement_msg Achievements: " + local.player.achievement + " / 20 Points");
    local.player stufftext "globalwidgetcommand credits1 linkcvar achievement_msg"
    local.player stufftext "showmenu credits1"
    
    
            }
        }
        wait 1
    }
    
    end
    Thanks again.
    Last edited by OhGaz; October 14th, 2015 at 07:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •